﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZeroBug.EasyFlow.Core;

namespace ZeroBug.EasyFlow.Step
{
    public class SwitchStep : IStep
    {
        public bool IsSingleRun { get; set; }
        public bool IgnoreChildren { get; set; }
        public string Icon { get; set; } = "FlowTree";
        public int ChildrenIndex { get; set; }
        public Core.Step? NextStep { get; set; }
        public bool Compile(FlowBase flow, Core.Step step, out string errInfo)
        {
            errInfo = "";
            return true;
        }

        public object GetForm()
        {
            throw new NotImplementedException();
        }

        public StepInfo GetInfo()
        {
            StepInfo info = new StepInfo();
            info.StepName = "Switch";
            info.Group = StepGroup.Control;
            info.ImagePath = "pack://application:,,,/ZeroBug.EasyFlow.Step;component/Images/条件.png";
            return info;
        }

        public void OnChildrenEnter()
        {

        }

        public void OnChildrenLeave()
        {

        }

        public bool Prepare(FlowBase flow, Core.Step step, out string errInfo)
        {
            errInfo = "";
            return true;
        }

        public void RegisterVariables(FlowBase flow, Core.Step step)
        {

        }

        public StepResult Run(FlowBase flow, Core.Step step, out string errInfo)
        {
            errInfo = "";

            IsSingleRun = true;
            IgnoreChildren = false;

            for (int i = 0; i < step.Conditions.Count; i++)
            {
                if (step.Conditions[i].Result)
                {
                    ChildrenIndex = i;
                    break;
                }
            }
            Thread.Sleep(500);

            return StepResult.Success;
        }

        public string GetTip(Core.Step step)
        {
            return "";
        }

        public (SerializableDictionary<string, VariableExpression>, List<VariableJudge>) GetParametersAndConditions()
        {
            throw new NotImplementedException();
        }

        public void UnRegisterVariables(FlowBase flow, Core.Step step)
        {
        }
    }
}
